<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/tabs.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<%@ include file="/commons/dateTime.jsp"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>批量收费添加</title>
<script type="text/javascript" src="${ctx}/scripts/jquery.js"></script>
<script language="JavaScript" type="text/javascript"
	src=".${ctx}/js/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/show.js"></script>
<script language="JavaScript" type="text/javascript"
	src="${ctx}/scripts/global.js"></script>

<link href="${ctx}/styles/listTable.css" rel="stylesheet"
	type="text/css" />
<link href="${ctx}/styles/grid.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>

<link href="${ctx}/css/show.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/public.css" rel="stylesheet" type="text/css">
<link href="${ctx}/css/aux_window.css" rel="stylesheet" type="text/css">

<script type="text/javascript">

	
	function getHouseOwner(){
		jQuery.noConflict();
		var houseNumber = document.getElementById('houseNumber').value;
		if(houseNumber==null || houseNumber==''){
		
		}else{
				jQuery.ajax({
					type:'GET',
					url	:"${ctx}/charge_cashieringAction.do?method=findHouseOwnerByHouseNumber&number="+encodeURI(encodeURI(houseNumber)),
					dataType:'text',
					success:function(json){
						var name=json;
						if(name==null || name=="" || name=="null"){
							FailureAlert('输入房号有误,请重试!');
							hiddenLoading();
						}else{
							jQuery('#houseOwner').val(name);
						}
					},
					error:function(error){
						FailureAlert('输入房号有误,请重试。');
						hiddenLoading();
					}
				});
		}
	}
	
	function showResponseDelete(transport){
		ajaxSubmitException(transport.responseText);
		if(transport.responseText==null || transport.responseText=='' ){
			Alert('请输入正确的房号');
		}else{
			alert(encodeURI(transport.responseText));
			document.getElementById('houseOwner').value=transport.responseText;
		}
	}
	
	function getTotal(){
	
		showLoading("项目正在添加中，请稍候...");

		var parent = findFrame('listPageIfm');
		var houseNumber = document.getElementById('houseNumber').value;
		var periodId = document.getElementById('payDate').value;
		var codeId = document.getElementById('codeId').value;
		var ownerName = document.getElementById('houseOwner').value;
		if(ownerName==null || ownerName==""){
				Alert("用户名不能为空！");
				hiddenLoading();
		}else{
				if(trim(ownerName).length >= 2){
				
					parent.appendDataByName(trim(houseNumber),trim(ownerName),periodId,codeId);
						
				}else{
					Alert('业主名不能为空或长度过短，请重新输入！');
					hiddenLoading();
					return false;
				}
		}
		
	}
	
	function trim(str){  //删除左右两端的空格
  		 return str.replace(/(^\s*)|(\s*$)/g, "");
 	}
	
	function changePeriod(period){
		var ownerName = jQuery('#houseOwner').val();

		if(period.value==9999){
			var url="${ctx}/charge_cashieringAction.do?method=getPeriodList&ownerName="+ownerName;
			top.windowOpen(url,"addPeriods","选择周期",230,400);
		}else if(period.value==0){
			jQuery("#payDate").val(0);
			jQuery("#selectPeriod").html("");
		}
	}
	
	function selectPeriodsValues(periodsValues){
		jQuery("#payDate").val(periodsValues);
		var temp1 = "";
		var temp2 = "";
		
		if(periodsValues.length>28 && periodsValues.length<=56){
			temp1 = periodsValues.substring(0,27);	
			temp2 = periodsValues.substring(28);
			jQuery("#selectPeriod").html(temp1+"<br/>"+temp2.substring(0,temp2.length-1));
		}else if(periodsValues.length>56){
			temp1 = periodsValues.substring(0,27);	
			temp2 = periodsValues.substring(28,55);		
			var temp3 =periodsValues.substring(56);	
			jQuery("#selectPeriod").html(temp1+"<br/>"+temp2+"<br/>"+temp3.substring(0,temp3.length-1));
		}else{
			jQuery("#selectPeriod").html(periodsValues.substring(0,periodsValues.length-1));
		}
	}
	
	function validateHouseOwner(thisOwner){
		var ownerName = trim(thisOwner.value);
		var urlName = "${ctx}/charge_cashieringAction.do?method=validateHouseOwner&ownerName="+encodeURI(encodeURI(ownerName));
		if(ownerName=null || ownerName == ""){
			Alert("请输入业主名或通过输入有效房号获取!");
			return false;
		}else{
			jQuery.ajax({
					type:'GET',
					url	:urlName,
					dataType:'text',
					success:function(result){
						if(result=="noSuchOwner"||result==null || result=="" || result=="null"){
							//FailureAlert('输入业主不存在,请重试!');
							return false;
						}else if(result == "valid"){
							return true;
						}
					},
					error:function(error){
						//FailureAlert('输入业主不存在,请重试！');
						return false;
					}
				});
		}
		
	}
	
	function validateHouseOwnerOnChange(thisOwner){
		var result = validateHouseOwner(thisOwner);
		alert(result);
		if(result){
			Alert("valid .");
		}else{
			Alert("用户名无效，请重新输入!");
			return;
		}
	}
	
	
	
</script>

</head>

<body>
<form id="monthlyStatementForm" name="monthlyStatementForm"
	method="post"
	action="${ctx}/charge_preparePayAction.do?method=doOffset"
	class="required-validate">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="window_head_outBg">
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td><img src="${ctx}/images/ico_Advance.gif" width="16"
					height="16" align="absmiddle" /> <span class="window_head_intext">批量缴费</span></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="aux_header_line_1"></td>
	</tr>
	<tr>
		<td class="aux_header_line_2"></td>
	</tr>
	<tr>
		<td class="content">

		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="aux_outtable_color">
				<table width="100%" border="0" cellpadding="0" cellspacing="1"
					class="aux_intable_color">
					<tr>
						<td class="aux_intable_td1">房号：</td>
						<td><input name="houseNumber" id="houseNumber" type="text"
							size="16" onblur="getHouseOwner();" /></td>
					</tr>
					<tr>
						<td class="aux_intable_td1">业主：</td>
						<td class="aux_intable_require"><input name="houseOwner"
							id="houseOwner" type="text" class="required min-length-2"
							size="16"
							validateMessage="业主不能为空" /></td>
					</tr>
					<tr>
						<td class="aux_intable_td1">收费周期：</td>
						<td class="aux_intable_require"><select
							onChange="changePeriod(this);">
							<option value="0">全部</option>
							<option value="9999">选择具体周期</option>
						</select> <input id="payDate" name="payDate" type="hidden" value="0"></input>
						<table>
							<tr>
								<td id="selectPeriod" width="100px"></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td class="aux_intable_td1">支付交易码：</td>
						<td class="aux_intable_require"><select id="codeId"
							name="codeId">
							<c:forEach items="${codeList}" var="code">
								<option value="${code.keyword}">${code.bizCode
								}-${code.description}</option>
							</c:forEach>
						</select></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>

		</td>
	</tr>
	<tr>
		<td class="window_footer">
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="btn_between_space">&nbsp;</td>
				<td>
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="buttonOffLeft" id="btn1_21"></td>
						<td class="buttonOffMiddle" id="btn1_22" onClick="getTotal();"
							onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)"
							onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif"
							alt="" width="14" height="14" border="0" align="absbottom" />确定</td>
						<td class="buttonOffRight" id="btn1_23"></td>
					</tr>
				</table>
				</td>
				<td class="btn_between_space"></td>
				<td>
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="buttonOffLeft" id="btn1_31"></td>
						<td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();"
							onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"
							onBlur="btn_change(3)"><img
							src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14"
							border="0" align="absbottom" /> 关 闭</td>
						<td class="buttonOffRight" id="btn1_33"></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</form>


</body>
</html>